
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class InnoRole
    /// </summary>
    [Serializable]
    public partial class InnoRole : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual System.Guid Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_Application.
        /// </summary>
        /// <value>The FK_Application.</value>
        /// <remarks>
        /// Foregn key of InnoRole
        /// 
        /// </remarks>
        public virtual System.Guid FK_Application
        {
            get { return _fK_Application; }
            set
            {
                if (_fK_Application != value)
                {
                    if (InnoApplication != null && InnoApplication.Id != value)
                    {
                        InnoApplication = null;
                    }
                    _fK_Application = value;
                }
            }
        }
        private System.Guid _fK_Application;
    	
        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        /// <value>The Name.</value>
        public virtual string Name
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
        public virtual InnoApplication InnoApplication
        {
            get { return _innoApplication; }
            set
            {
                if (!ReferenceEquals(_innoApplication, value))
                {
                    var previousValue = _innoApplication;
                    _innoApplication = value;
                    FixupInnoApplication(previousValue);
                }
            }
        }
        private InnoApplication _innoApplication;
    
        /// <summary>
        /// Link InnoRole to all InnoUsersInRoles
        /// </summary>
        public virtual ICollection<InnoUsersInRoles> InnoUsersInRoles
        {
            get
            {
                if (_innoUsersInRoles == null)
                {
                    var newCollection = new FixupCollection<InnoUsersInRoles>();
                    newCollection.CollectionChanged += FixupInnoUsersInRoles;
                    _innoUsersInRoles = newCollection;
                }
                return _innoUsersInRoles;
            }
            set
            {
                if (!ReferenceEquals(_innoUsersInRoles, value))
                {
                    var previousValue = _innoUsersInRoles as FixupCollection<InnoUsersInRoles>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupInnoUsersInRoles;
                    }
                    _innoUsersInRoles = value;
                    var newValue = value as FixupCollection<InnoUsersInRoles>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupInnoUsersInRoles;
                    }
                }
            }
        }
        private ICollection<InnoUsersInRoles> _innoUsersInRoles;

        #endregion

        #region Association Fixup
    
        private void FixupInnoApplication(InnoApplication previousValue)
        {
            if (previousValue != null && previousValue.InnoRole.Contains(this))
            {
                previousValue.InnoRole.Remove(this);
            }
    
            if (InnoApplication != null)
            {
                if (!InnoApplication.InnoRole.Contains(this))
                {
                    InnoApplication.InnoRole.Add(this);
                }
                if (FK_Application != InnoApplication.Id)
                {
                    FK_Application = InnoApplication.Id;
                }
            }
        }
    
        private void FixupInnoUsersInRoles(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (InnoUsersInRoles item in e.NewItems)
                {
                    item.InnoRole = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (InnoUsersInRoles item in e.OldItems)
                {
                    if (ReferenceEquals(item.InnoRole, this))
                    {
                        item.InnoRole = null;
                    }
                }
            }
        }

        #endregion

    }
}
